package com.security;

import com.utils.RestResponse;
import com.utils.ResultCode;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

/**
 * @author t-zhaoheng
 * @since 2022/3/29
 */
@Component
@Slf4j
public class MyAuthenticationEntryPoint extends JSONAuthentication implements AuthenticationEntryPoint {

  @Override
  public void commence(HttpServletRequest request, HttpServletResponse response,
      AuthenticationException authException) throws IOException {
    this.writeJSON(response, RestResponse.fail(ResultCode.TOKEN_INVALID));
  }
}
